package com.letfox.redis.util;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
public class ValueOperationUtil<T> {

	@Resource(name = "redisTemplate")
	private RedisTemplate<String, T> redisTemplate;

	/**
     * 缓存基本的对象
     * @param key    缓存的键值
     * @param value 缓存的值
     * @return 缓存的对象
     */
	public ValueOperations<String, T> setCacheObject(String key, T value) {
		ValueOperations<String, T> operation = redisTemplate.opsForValue();
		operation.set(key, value);
		return operation;
	}
	
	/**
     * 获得缓存的基本对象
     * @param key 缓存键值
     * @return 缓存键值对应的数据
     */
	public T getChcheObject(String key){
		ValueOperations<String, T> operation = redisTemplate.opsForValue();
		return operation.get(key);
	}
	
	
}
